package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceSettlementStatementEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年12月19日 上午10:11:31
*@author wenwenlong
*类说明
*/

@Implements(FinanceSettlementStatementService.class)
public class FinanceSettlementStatementServiceImpl implements FinanceSettlementStatementService {

	@Override
	public Long createFinanceSettlementStatement(FinanceSettlementStatementEntity entity) {
		entity.setEnabled(Boolean.TRUE);
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.insert(entity);
		return entity.getSettlementStatementId();
	}

	@Override
	public void updateFinanceSettlementStatement(FinanceSettlementStatementEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public void disabledFinanceSettlementStatement(Long settlementStatementId) {
		FinanceSettlementStatementEntity entity = inquireFinanceSettlementStatement(settlementStatementId);
		entity.setEnabled(Boolean.FALSE);
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public FinanceSettlementStatementEntity inquireFinanceSettlementStatement(Long settlementStatementId) {
		return PersistUtil.get(FinanceSettlementStatementEntity.class, settlementStatementId);
	}

	@Override
	public PageList<FinanceSettlementStatementEntity> inquireFinanceSettlementStatementPageList(PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceSettlementStatementEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		return PersistUtil.get(criteria, page);
	}

	@Override
	public List<FinanceSettlementStatementEntity> inquireFinanceSettlementStatementList(Long monthEarningId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceSettlementStatementEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		if (null != monthEarningId) {
			criteria.add(Restrictions.eq("monthEarningId", monthEarningId));
		}
		return PersistUtil.get(criteria);
	}
}
